<?php
namespace app\common\tool;

use app\common\model\Post as PostModel;
use app\common\model\PostClass as PostClassModel;


class Query{

    /**
     * 获取文章列表
     */
    public function paginatePostsByMark($mark=null,$pageSize=20,$page=1){
        //find the class by mark
        $postClasses = PostClassModel::where("mark",$mark)->select();
        $postClasses = collection($postClasses)->toArray();
        $pcIds = [];
        foreach($postClasses as $key => $val ){
            $pcIds[] = $val['id'];
        }
        $posts = PostModel::whereIn("pc_id",$pcIds)->order('id desc')->paginate($pageSize,false,['page'=>$page]);
        return $posts;
    }

    /**
     * 根据文章的分类 获取文章列表
     */
    public function paginatePostsByPcId($id = 0,$pageSize = 20,$page = 1){
        $posts = PostModel::where('pc_id',$id)->order('id desc')->paginate($pageSize,false,['page'=>$page]);
        return $posts;
    }
}